
#include "bird.h"
#include<QTimer>

Bird::Bird(QWidget *parent)
    : QWidget{parent}
{
    //加载鸟的图片
    for(int i=0;i<this->max;i++)
    {
        QString s=QString(":/Bird/bird%1").arg(i+1);//%1叫占位符
        this->m_Bird_Pix.load(s);
    }

    //设置鸟的尺寸(防止图片过大），后面还有设置窗口的尺寸
    this->setFixedSize(this->m_Bird_Pix.width(),this->m_Bird_Pix.height());

    //创建定时器的对象
    this->timer=new QTimer(this);

    //监听定时器发的信号
    connect(timer,&QTimer::timeout,[=](){
        QString s=QString(":/Bird/bird%1").arg(this->min++);
                    this->m_Bird_Pix.load(s);
        if(this->min>this->max)
        {
                        this->min=1;
        }
        //每次切图都要触发信号，让主场景收到
        emit changePix();
    });

}

void Bird::running()
{
    //启动定时器
    this->timer->start(50);
}
